package com.diandi.signature.service.impl.contract;

import com.diandi.signature.bean.contract.SignatureContract;
import com.diandi.signature.contract.FddUploadContractService;
import com.diandi.signature.fddtools.FddUtil;
import com.diandi.signature.manager.contract.FddUploadContractManager;
import com.diandi.signature.url.GsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
* @author mwz
* @create 2017-08-31 20:08
* @version V1.0.0
* @description description
*/
@Service
public class FddUploadContractServiceImpl implements FddUploadContractService {
     private static Logger logger = LoggerFactory.getLogger(FddUploadContractServiceImpl.class);

    @Autowired
    FddUploadContractManager fddUploadContractManager;
    @Override
    public Map<String, String> FddUploadContract( SignatureContract signatureContract, Map<String, String> params, Map<String,String> parmMap ,Integer processFlag)   {

        String platTradeNo = parmMap.get("platTradeNo");
        logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]：开始处理上传文档"+parmMap.toString()+"--");
        try{
            /**
             * 1.1 记录中间状态
             */
            //fddUploadContractManager.insertProcessInfoData(signatureContract,params,processFlag);

            /**
             * 2.1 上传文档
             */
            String contractNo = parmMap.get("contractNo");
            File file = new File( parmMap.get("file") );
            String docType = ".doc";
            Map<String,String> returnMap =  new HashMap<String,String>();
            String result = FddUtil.invokeUploadDocs(   contractNo,   file,   docType);

            returnMap = GsonUtil.fronJson2Map(result);

            /**
             * 3.1 更新中间状态
             */
            //fddUploadContractManager.updateProcessInfoData(signatureContract,params,processFlag);
            logger.info("--rcv:platTradeNo:"+platTradeNo+":[合同创建]:结束处理上传文档result："+result+"--");
            return returnMap;
        }catch (Exception e){
            e.printStackTrace();
            //fddUploadContractManager.updateProcessInfoData(signatureContract,params,processFlag);
        }


        return params;
    }


}